package de.androidDevelopers.communityTeacherApp.models;

import java.util.List;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteStatement;

import de.greenrobot.dao.AbstractDao;
import de.greenrobot.dao.Property;
import de.greenrobot.dao.internal.DaoConfig;
import de.greenrobot.dao.query.Query;
import de.greenrobot.dao.query.QueryBuilder;

import de.androidDevelopers.communityTeacherApp.models.ContactInfo;

// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
/** 
 * DAO for table CONTACT_INFO.
*/
public class ContactInfoDao extends AbstractDao<ContactInfo, Long> {

    public static final String TABLENAME = "CONTACT_INFO";

    /**
     * Properties of entity ContactInfo.<br/>
     * Can be used for QueryBuilder and for referencing column names.
    */
    public static class Properties {
        public final static Property Id = new Property(0, Long.class, "id", true, "_id");
        public final static Property Name = new Property(1, String.class, "Name", false, "NAME");
        public final static Property Adress = new Property(2, String.class, "Adress", false, "ADRESS");
        public final static Property Relation = new Property(3, String.class, "Relation", false, "RELATION");
        public final static Property Phone = new Property(4, String.class, "Phone", false, "PHONE");
        public final static Property ContactInfoFK = new Property(5, Long.class, "ContactInfoFK", false, "CONTACT_INFO_FK");
    };

    private Query<ContactInfo> pupilInfo_ContactInfoListQuery;

    public ContactInfoDao(DaoConfig config) {
        super(config);
    }
    
    public ContactInfoDao(DaoConfig config, DaoSession daoSession) {
        super(config, daoSession);
    }

    /** Creates the underlying database table. */
    public static void createTable(SQLiteDatabase db, boolean ifNotExists) {
        String constraint = ifNotExists? "IF NOT EXISTS ": "";
        db.execSQL("CREATE TABLE " + constraint + "'CONTACT_INFO' (" + //
                "'_id' INTEGER PRIMARY KEY ," + // 0: id
                "'NAME' TEXT," + // 1: Name
                "'ADRESS' TEXT," + // 2: Adress
                "'RELATION' TEXT," + // 3: Relation
                "'PHONE' TEXT," + // 4: Phone
                "'CONTACT_INFO_FK' INTEGER);"); // 5: ContactInfoFK
    }

    /** Drops the underlying database table. */
    public static void dropTable(SQLiteDatabase db, boolean ifExists) {
        String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "'CONTACT_INFO'";
        db.execSQL(sql);
    }

    /** @inheritdoc */
    @Override
    protected void bindValues(SQLiteStatement stmt, ContactInfo entity) {
        stmt.clearBindings();
 
        Long id = entity.getId();
        if (id != null) {
            stmt.bindLong(1, id);
        }
 
        String Name = entity.getName();
        if (Name != null) {
            stmt.bindString(2, Name);
        }
 
        String Adress = entity.getAdress();
        if (Adress != null) {
            stmt.bindString(3, Adress);
        }
 
        String Relation = entity.getRelation();
        if (Relation != null) {
            stmt.bindString(4, Relation);
        }
 
        String Phone = entity.getPhone();
        if (Phone != null) {
            stmt.bindString(5, Phone);
        }
    }

    /** @inheritdoc */
    @Override
    public Long readKey(Cursor cursor, int offset) {
        return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0);
    }    

    /** @inheritdoc */
    @Override
    public ContactInfo readEntity(Cursor cursor, int offset) {
        ContactInfo entity = new ContactInfo( //
            cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id
            cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // Name
            cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // Adress
            cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // Relation
            cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4) // Phone
        );
        return entity;
    }
     
    /** @inheritdoc */
    @Override
    public void readEntity(Cursor cursor, ContactInfo entity, int offset) {
        entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0));
        entity.setName(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1));
        entity.setAdress(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2));
        entity.setRelation(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3));
        entity.setPhone(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4));
     }
    
    /** @inheritdoc */
    @Override
    protected Long updateKeyAfterInsert(ContactInfo entity, long rowId) {
        entity.setId(rowId);
        return rowId;
    }
    
    /** @inheritdoc */
    @Override
    public Long getKey(ContactInfo entity) {
        if(entity != null) {
            return entity.getId();
        } else {
            return null;
        }
    }

    /** @inheritdoc */
    @Override    
    protected boolean isEntityUpdateable() {
        return true;
    }
    
    /** Internal query to resolve the "contactInfoList" to-many relationship of PupilInfo. */
    public List<ContactInfo> _queryPupilInfo_ContactInfoList(Long ContactInfoFK) {
        synchronized (this) {
            if (pupilInfo_ContactInfoListQuery == null) {
                QueryBuilder<ContactInfo> queryBuilder = queryBuilder();
                queryBuilder.where(Properties.ContactInfoFK.eq(null));
                pupilInfo_ContactInfoListQuery = queryBuilder.build();
            }
        }
        Query<ContactInfo> query = pupilInfo_ContactInfoListQuery.forCurrentThread();
        query.setParameter(0, ContactInfoFK);
        return query.list();
    }

}
